<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="shortcut icon" href="../../../favicon.ico" type="image/x-icon">
	<title>callback_refs</title>
</head>
<body>
  <div id="test"></div>

  <script type="text/javascript" src="../../../js/react.development.js" ></script>
  <script type="text/javascript" src="../../../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../../../js/babel.min.js"></script>
  <script type="text/javascript" src="../../../js/prop-types.js"></script>

  <script type="text/babel">
    class Demo extends React.Component {
      state = {isCool: true}

      changeWeather = ()=>{
        this.setState({
          isCool: !this.state.isCool
        })
        this.weather = this.state.isCool?"寒冷":"炎热"
      }

      saveNode = (n)=>{
        console.log("@", n)
      }

      // 回调ref以内联函数形式定义,在更新页面时会调用两次,第一次入参为null,第二次正常
      render(){
        return (<div>
          {/* 
          回调ref以内联函数形式定义,在更新页面时会调用两次,第一次入参为null,第二次正常
          <h2 ref={(n)=>{console.log("@", n)}} >今天天气: {this.weather}</h2>
          */}
          <h2 ref={this.saveNode} >今天天气: {this.weather}</h2>
          <button onClick={this.changeWeather}>点击我改变天气</button>
          </div>)
      }
    }

    ReactDOM.render(<Demo />, document.getElementById('test'));
  </script>
</body>